
package com.gemframework.modules.prekit.auth.controller;
import com.gemframework.common.annotation.ApiLog;
import com.gemframework.common.utils.GemValidateUtils;
import com.gemframework.model.common.BaseResultData;
import com.gemframework.model.response.AccessTokenResponse;
import com.gemframework.model.response.RefreshTokenResponse;
import com.gemframework.modules.prekit.auth.entity.request.AccountPasswordAuthRequest;
import com.gemframework.modules.prekit.sys.entity.request.MemberSetPasswordRequest;
import com.gemframework.modules.prekit.auth.entity.request.RefreshAccessTokenRequest;
import com.gemframework.service.MemberService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.NotBlank;

@RestController
@CrossOrigin
public class AuthTokenApi {

	@Resource
	private MemberService memberService;


	@ApiLog(name = "获取token")
	@PostMapping("getAccessToken")
//	@ApiSign
	public BaseResultData getAccessTokenByAccount(@RequestBody AccountPasswordAuthRequest request) {
        //参数校验器
		GemValidateUtils.GemValidate(request);
		AccessTokenResponse data = memberService.getAccessTokenByAccount(request.getAccount(),request.getPassword());
		return BaseResultData.SUCCESS(data);
	}

	@ApiLog(name = "刷新token")
	@GetMapping("refreshAccessToken")
//	@ApiSign
	public BaseResultData refreshAccessToken(@RequestBody RefreshAccessTokenRequest request) {
		//参数校验器
		GemValidateUtils.GemValidate(request);
		RefreshTokenResponse data = memberService.refreshAccessToken(request.getMemberId(),request.getRefreshToken());
		return BaseResultData.SUCCESS(data);
	}

}
